package com.woniuxy.product.dao;

import com.woniuxy.common.entity.Product;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: 曾令忠
 * @Description:
 * @Date: 2020/7/10 0010-下午 10:44
 */
@Repository
public interface ProductDao {
    @Select("select * from product")
    @Results({
            @Result(id = true,column = "pid",property = "pid"),
            @Result(column = "pid",property = "images",many = @Many(select = "findImagesByPid"))
    })
    List<Product> getAll();

    @Select("select * from product where pid=#{id}")
    @Results({
            @Result(id = true,column = "pid",property = "pid"),
            @Result(column = "pid",property = "images",many = @Many(select = "findImagesByPid")),
            @Result(column = "pid",property = "types",many = @Many(select = "findTypeByPid"))
    })
    Product findProductyId(int pid);

    @Delete("delete from product where pid=#{id}")
    int delById(int id);


    //查询图片
    @Select("select name from images where pid = #{pid}")
    public List<String> findImagesByPid(int pid);

    //查询商品的类型
    @Select("select productType from producttype where pid = #{pid}")
    public List<String> findTypeByPid(int pid);
}
